Custom menus

SNiFF+ allows the definition of custom menus for the Source Editor and Project Editor. Custom menus are defined in a custom menus file which can be located either in a user's home directory or in the SNiFF+ installation directory for site-wide custom menus. The custom menu file is called,

- On Unix:

$HOME/.sniffrc/UserMenus.sniff or $SNIFF_DIR/config/SiteMenus.sniff .
- On Windows:
%SNIFF_DIR%\Profiles\<Username>\UserMenus.sniff or %SNIFF_DIR%\config\SiteMenus.sniff .
SNiFF+ searches first for the user-level and then for the site-level custom menu file. The custom menu files are loaded during start-up.
If there are more than 20 entries, the menu can be scrolled by dragging the mouse below the menu border.
Custom menu file format
The custom menu file can define more than one custom menu for each SNiFF+ tool. A new menu is defined by preceding its title with the " > " character. If the first menu does not have a title, its title will be set to Custom.

CustomMenuFile | = | { ToolFrame }
ToolFrame | = | ToolSpec { MenuSpec { MenuEntry } }
ToolSpec | = | "^" ( "Editor" | "ProjectEditor" ) NL
MenuSpec | = | ">" MenuLabel NL
MenuEntry | = | ( SimpleAction | InteractiveAction |Separator ) NL
SimpleAction | = | ( "shell" | "filter" | "debugger" | "python" )
|  | '"' MenuEntryName '"' '"' MenuEntryAction '"'
InteractiveAction | = | ( "FileNameDialog" | "DirectoryNameDialog" |
|  | "YesNoDialog" ) '"' MenuEntryName '"'
|  | '"' MenyEntryAction '"' '"' PromptMessage'"'
|  | |"AskQuestionDialog" '"' MenuEntryName '"'
|  | '"' MenyEntryAction '"' '"' PromptMessage'"'
|  | [ '"'DefaultValue'" ]
MenuEntryName | = | MenuEntryString [ Accelerator ]
MenuEntryAction | = | String that can contain % variables
Accelerator | = | "@" Character
Separator | = | "-"
NL | = | newline

A

shell command is executed in a SNiFF+ Shell tool.
A debugger command is sent to the Debugger.
A python command is executed by the python interpreter.
A filter command is any kind of process. Its input is the current selection in the Source Editor and its output replaces the current selection.
A separator causes the insertion of a line in the menu. It is used for aesthetic reasons only.
Strings may be delimited with double quotes ("") if they contain blanks.
All menu actions ( 'shell', 'debugger', 'FileNameDialog' , etc.) can now be extended by '*' or '**' , for example, shell*, python** (no blanks before * and **):

* | all file-dependent variables in the command will be expanded for the selected files. Project dependent variables are expanded using the root project data. The menu action will be executed once only.
** | the selected files are grouped by project. For each project, the file dependent variables are expanded for all selected files (of the project). The menu action will then be executed for each project that is referenced by the selected files.

| Note
| This convention is disabled for 'filter' commands.

Commands are executed in the shell and can contain the following variables:

%A | repository file of selected file
%C | file category directory (dot, if there isn't one)
%d | full path of project description file (PDF)
%D or %W | absolute private project directory
%e | sniffaccess project name format (see Project name format)
%E | working environment name
%f | full path of source file
%F | name of source file
%g | Shared Object Working Environments (same as in CMVC interface)
%G | Shared Source Working Environments (same as in CMVC interface)
%H | Shared Source Working Environment root directories, separated by semicolon
%i | session id of the SNiFF+ session
%k | selected class/union/struct
%l | locking path of project
%m | selected method
%N | number of expanded files (only for * or ** commands)
%p | Root Main Target (of the current root project)
%P | Main Target (of the project whose files you are currently working on)
%R | Repository Working Environment root directory
%s | a selection, single-quoted and with conversions
%S | a selection, as is
%t | the parameter, single-quoted and with conversions
%T | the parameter, as is
%V | selected file version (in the Project Editor's History window)
%w | Private Working Environment root directory

Lines in the menu files may contain comments. A comment starts with an unquoted number sign (#) and ends with the next newline.
Examples:

# this is a comment
shell "echo %s" "echo %s" # Just output the current selection
Interactive Actions
Shell commands can get information from the user via dialog boxes. The format of the commands is:
<command> <menu_item_string> <shell_command> <prompt_string> [<defaul_value>]
Notice that the format is the same as the shell command, but there is a supplementary prompt string.
The <command> may be one of: AskQuestionDialog, YesNoDialog, FileNameDialog or DirectoryNameDialog .

AskQuestionDialog | Presents a prompt string to the user and expects an answer. If Cancel is hit, the command is aborted and the script is not invoked. If OK is pressed the input from user is passed to the shell as %t .
YesNoDialog | Displays a question and prompts for Yes/No/Cancel. Cancel aborts without running the script; otherwise the %t variable is set to YES or NO and the shell command is called.
FileNameDialog | Presents SNiFF+'s standard File dialog with the specified prompt. The name of the selected file is passed to the shell as %t .
DirectoryNameDialog | Prompts the user to select a directory using SNiFF+'s standard Directory dialog. The name of the selected directory is passed to the shell as %t .
<menu_item_string> | Displayed in the . Variables (for example %f ) as shown above can be used.
<shell_command> | Command given to the shell. There is a supplementary variable %t . Its value is the user input (depending on the <command> ). In %t , newline characters are replaced with the string " \n " to protect them from being interpreted by the shell.
<prompt_string> | Prompt string which is displayed in the dialog boxes. Variables (for example %f ) as shown above can be used.
<default_value> | Valid for the AskQuestionDialog and is the default value which can also contain the above mentioned variables.

Examples
The following example defines a menu called Custom in the Project Editor

# Example file for a "Custom" menu in the Project Editor # ^ ProjectEditor > Custom shell "RCS diff" "rcsdiff -kk %l/RCS/%F,v %f" shell "SCCS diff" "cd %D; sccs -d%l diffs %F" - filter Date date shell "Load File Into vi" "cmdtool vi %f" - FileNameDialog "Launch Document..." "open_document %t" "Choose a document to launch:" AskQuestionDialog "Special Checkin..." "check_in -version %t %f" "Enter checkin version:" "%V" YesNoDialog "Cancel Checkout..." "cancel_checkout %t %f" "Are you sure you want to cancel your checkout of %f?" - debugger "Info Files" "info files"

The following example defines two menus for the Source Editor. The first menu is called Echo; the second is called Misc:

# Example menu file for two Editor menus # ^ Editor > Echo shell "echo %s" "echo %s" shell "echo %d" "echo %d" shell "echo %f" "echo %f" shell "echo %D" "echo %D" shell "echo %F" "echo %F" shell "echo %l" "echo %l" - filter "date" "date" > Misc DirectoryNameDialog "Clean Directory..." "clean_directory %t" "Choose a directory to clean:" - shell "Command 1" "echo 1" shell "Command 2" "echo 2"

It is now possible to use back slashes at the end of a line, inside double quotes, to logically continue the line. For example:
python "Greeting"
"print 'Welcome to SNiFF+' \
print 'This is an example Custom menu'"